from BackTestingRunner import BackTestingRunner
from Strategy import Strategy


class SimpleStrategy(Strategy):
    def __init__(self):
        super().__init__()

    def onKlineStep(self, index, context):
        """
        测试买卖: index 逢 10 的倍数买入， 逢 15 倍数卖出
        """
        if index % 10 == 0:
            if self.repo.getKeepNum() == 0:
                self.repo.buyByRate(1, index)
        elif index % 15 == 0:
            if self.repo.getKeepNum() > 0:
                self.repo.sellByRate(1, index)


BackTestingRunner('sh000001', 180, '2024-11-01').start(SimpleStrategy(), 500000)
